﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace PassportManage
{
    public partial class Form_Login : Form
    {
        public static Form ff;
        public Form_Login()
        {
            InitializeComponent();
        }
        public Form_Login(Form f)
        {
            InitializeComponent();
            this.CenterToScreen();
            this.tex_pwd.PasswordChar = '*';
            this.tex_User.TabIndex = 0;
            this.tex_pwd.TabIndex = 1;
            this.btn_log.TabIndex = 2;
            this.btn_can.TabIndex = 3;
            ff = f;
            this.FormBorderStyle = FormBorderStyle.None;
        }
        private void log()
        {
            //AdminInfo admin = AdminServices.LoginAdmin(this.tex_User.Text, this.tex_pwd.Text);
            // MessageBox.Show(admin.Adminname);
            try
            {                
                if (!string.IsNullOrEmpty(this.tex_User.Text) && !string.IsNullOrEmpty(this.tex_pwd.Text))
                {
//                     BLL.UserLogin.UserLogin ls = new BLL.UserLogin.UserLogin();
//                     ls.CookieContainer = BLL.GetPassportInfoFormServer.cookie;
//                     BLL.UserLogin.OperationReturn ret = ls.login(this.tex_User.Text, this.tex_pwd.Text);
                    BLL.MyUserLogin.UserLogin ls = new BLL.MyUserLogin.UserLogin();
                    BLL.MyUserLogin.OperationReturn ret = ls.login(this.tex_User.Text, this.tex_pwd.Text);
                    if(ret.returnCode=="00000")
                    {                        
                        Form_Main f = new Form_Main(this.tex_User.Text, this);
                        f.Show();
                        this.Visible = false;
                    }
                    else
                    {
                        MessageBox.Show("登陆失败!!"+ret.returnCodeDesc);
                    }
                    
//                     if(Membership.ValidateUser(this.tex_User.Text,this.tex_pwd.Text))
//                     {
//                         Form_Main f = new Form_Main(this.tex_User.Text, this);
//                         f.Show();
//                         this.Visible = false;
//                     }
//                     else
//                     {
//                         MessageBox.Show("用户名或密码错误，请重新输入!!");
//                         this.tex_pwd.Text = "";
//                     }
                }
                else
                {
                    MessageBox.Show("用户名或密码不能为空!!");
                }
            }
            catch
            {
                MessageBox.Show("系统发生不明错误，请联系管理员！！");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //this.tex_User.Height = this.tex_pwd.Height;
            log();
            //  this.Visible = false;

        }

        private void btn_log_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void tex_pwd_KeyDown(object sender, KeyEventArgs e)
        {
//             if (e.KeyValue == 13)
//             {
//                 log();
//             }
        }
       
        private void Form_log_FormClosing(object sender, FormClosingEventArgs e)
        {

        }

        private void Form_log_FormClosed(object sender, FormClosedEventArgs e)
        {
            ff.Close();
        }
    }
}
